<?php
class EditUserSettingsForm extends Zend_Form
{
    public function init()
    {                
    	// Create an element to hold the name
   		$name = $this->createElement('text','name');
        $name->setLabel('Enter a new name :')
        	// Validate that the name contain only caracters, numbers, underscore and space and start with a letter
	        	->addValidator(new Zend_Validate_Regex("/^\w[\w ]*$/"))
    	    	->addValidator(new Zend_Validate_StringLength(0, 45));
		    
		// Create an element to hold the phone number
        $tel = $this->createElement('text','tel');
        $tel->setLabel('Enter a new Phone :')
        		// Check that the phone is in the good format : +CountryCode.PhoneNumber		
				->addValidator(new Perso_Validate_Phone())
				->addValidator(new Zend_Validate_StringLength(0, 45));
        
        // Create an element to hold the name
        $email = $this->createElement('text','email');
        $email->setLabel('Enter a new mail adress :')
        		// Check that the email is valid
                ->addValidator(new Zend_Validate_EmailAddress())
                ->addValidator(new Zend_Validate_StringLength(0, 45));
                
        // Create an element to hold the old password
		$oldPassword = $this->createElement('password','oldPassword');
        $oldPassword->setLabel('Please enter your old password: ')
	        	->addValidator(new Zend_Validate_StringLength(0, 20));
                        
        // Create an element to hold the new password
        $password = $this->createElement('password','password');
        $password->setLabel('Password: *')
                ->addValidator(new Zend_Validate_StringLength(6, 20));

        // Create an element to hold the confirmed password                
        $confirmPassword = $this->createElement('password','confirmPassword');
        $confirmPassword->setLabel('Confirm Password: *')
        		// Check that the confirm password match the password
                ->addValidator(new Perso_Validate_ElementConfirmation('password'))
                ->addValidator(new Zend_Validate_StringLength(6, 20));

        // Create an element to hold the submit button
		$register = $this->createElement('submit','register');
		$register->setLabel('Save preferences')
                ->setIgnore(true);
        
        // Add the form elements to the form
        $this->addElements(array(
                        $name,
                        $email,
						$tel,
						$oldPassword,
						$password,
						$confirmPassword,
        ));
        // Create a group (ie a fieldset) to hold the general user informations (name/phone/email)
        $this->addDisplayGroup(
        	array('name', 'tel','email'), // Elements to add to the group
        	'generalInformation',	// name of the group
        	array('legend'=>'General informations'));	// add a legend to the group
        	
        // Create a group (ie a fieldset) to hold the password change (oldPassword/password/confirmPassword)
        $this->addDisplayGroup(
        	array('oldPassword', 'password', 'confirmPassword'), // Elements to add to the group
        	'passwordChange', // name of the group
        	array('legend'=>'Change password')); // add a legend to the group

		// add the submit button
		$this->addElement($register);
    }
}

